package com.example.zzl.view.fragment.UserFragment;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.ListView;

/**
 * Created by Administrator on 2017/2/12.
 */

public class ListUtils {
    public static void setListViewHeight(ListView listView){
        ListAdapter adapter = listView.getAdapter();
        if (adapter==null){
            return;
        }
        int totalHeight=0;
        for (int i = 0; i < adapter.getCount(); i++) {
            View item=adapter.getView(i,null,listView);
            item.measure(0,0);
            totalHeight+=item.getMeasuredHeight();
        }
        ViewGroup.LayoutParams params=listView.getLayoutParams();
        params.height=totalHeight+(listView.getDividerHeight()*(adapter.getCount()-1));
        listView.setLayoutParams(params);
    }
}
